import { createRouter, createWebHashHistory } from 'vue-router'
import layout from '@/layout'
import store from '../store'
import SysManage from './modules/SysManage'
import Screen from './modules/Screen'
import ThreeDView from './modules/ThreeDView'
import RunMonitor from './modules/RunMonitor'
import EquipManage from './modules/EquipManage'
import OpsManage from './modules/OpsManage'
import DataManage from './modules/DataManage'
export const privateRoutes = [
  Screen,
  ThreeDView,
  RunMonitor,
  EquipManage,
  OpsManage,
  DataManage,
  SysManage,
]

/**
 * 公开路由表
 */
export const publicRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index')
  },
  // },

  {
    path: '/',
    component: layout,
    redirect: '/threeD/view',
    children: [
      // {
      //   path: '/home',
      //   name: 'homePage',
      //   component: () => import('@/views/back/home/index'),
      //   meta: {
      //     title: 'homePage',
      //     icon: 'personnel-manage'
      //   }
      {
        path: '/modify',
        name: 'modify',
        component: () => import('@/views/back/modify/index')
      },
      {
        path: '/404',
        name: '404',
        component: () => import('@/views/error-page/404')
      },
      {
        path: '/401',
        name: '401',
        component: () => import('@/views/error-page/401')
      }
    ]
  }
]

/**
 * 初始化路由表
 */
export function resetRouter() {
  if (
    store.getters.userInfo &&
    store.getters.userInfo.permission &&
    store.getters.userInfo.permission.menus
  ) {
    const menus = store.getters.userInfo.permission.menus
    menus.forEach((menu) => {
      router.removeRoute(menu)
    })
  }
}

const router = createRouter({
  history: createWebHashHistory(),
  routes: [...publicRoutes]
})

export default router
